<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>施工队信息管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../../../resources/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../resources/css/style.css" media="all">
    <style>
        .layui-form-select input{width: 100%;!important;}
        .layui-form-label{width: 100px;}
        .layui-input-block{margin-left: 140px;}
        #date1,#date2{margin-bottom: 10px;}
        ._submit{width: 100%;text-align: center;}

        .gongliao{display: none;}
        .layui-form-select .layui-input{padding-right: 0;}
        .layui-form-select{width: 160px;}
        .layui-form-select input{width: 190px;}
        .layui-form-label{text-align: left;}
        .bixuan{left: 4px;}
        ._submit{margin-bottom: 30px;}
        .masksx .forms{padding-left: 0;}
        .layui-form-item{margin-bottom: 10px;}
        /*
 设置样式居中
 */
        .mask .layui-form-item{padding-left:76px;}
        .layui-form-label{width: 100px;text-align: justify;height: 20px;}
        .layui-table-box{width: 102%;}
        .gongliao .layui-select-title{padding-left: 10px;}
        .gongliao .layui-form-select{width: 170px;}
        .buts{float: left;}
        .layui-form-item{clear: none;}
        .formTop .layui-form-item .layui-input-inline {width: 80%;}
        .layui-form-pane .layui-input-inline{width: 80%!important;}
    </style>
</head>
<body>
<form class="layui-form layui-form-pane" id="form_7grid" action="" >

    <div class="formTop" style="font-size:12px;">

        <div class="layui-form-item layui-col-md3 layui-col-sm3 layui-col-xs3">
            <div class="layui-input-inline">
                <input type="text" name="compname" lay-verify="required" placeholder="请输入企业名" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline layui-col-md3 layui-col-sm3 layui-col-xs3">
            <div class="layui-input-inline">
                <input type="text" class="layui-input" id="test-limit3" name="begintime" placeholder="请选择创建开始日期">
            </div>
        </div>
        <div class="layui-inline layui-col-md3 layui-col-sm3 layui-col-xs3">

            <div class="layui-input-inline">
                <input type="text" class="layui-input" id="test-limit4" name="endtime" placeholder="请选择创建结束日期">

            </div>
        </div>
        <div class="layui-col-md3 layui-col-sm3 layui-col-xs3">
            <button class="layui-btn tijiao" type="button" onclick="queryUser()">查询</button>
            <button class="layui-btn layui-btn-normal quanxian" type="button" style="background-color: #ff8f3b;" onclick="enterpriseAdd()" QX="api/comp/inComp.do">添加</button>
        </div>

    </div>

    <table id="demo" lay-filter="test"></table>

    <script type="text/html" id="barDemo">
        <a class="layui-btn  layui-btn-xs" lay-event="detail">查看</a>
        <a class="layui-btn layui-btn-danger quanxian layui-btn-xs" lay-event="edit" QX="api/comp/inComp.do">编辑</a>
    </script>

</form>
<a class="dayin" type="button" id="dlink" onclick="" style="float: right; position: fixed; right: 50px; bottom: 50px; z-index: 999;"></a>

    <div class="mask">
        <div class="masksx">
            <div class="title"><span class="titleL">添加用户</span><span class="close">×</span></div>
            <div class="forms">
              <form class="layui-form tianjiaqiye" action="" method="post">

                <div class="layui-form-item">
                    <label class="layui-form-label">企业全称：</label>
                    <div class="layui-input-block">
                        <input type="text" name="compname" lay-verify="required" autocomplete="off" placeholder="请输入企业全称" class="layui-input" value="">
                    </div>
                </div>
                <!--<div class="layui-form-item">-->
                    <!--<label class="layui-form-label">简称：</label>-->
                    <!--<div class="layui-input-block">-->
                        <!--<input type="text" name="shortname" lay-verify="required" autocomplete="off" placeholder="请输入标题" class="layui-input" value="">-->
                    <!--</div>-->
                <!--</div>-->
                <div class="layui-form-item">
                    <label class="layui-form-label">企业地址：</label>
                    <div class="layui-input-block">
                        <input type="text" name="addr" lay-verify="required" autocomplete="off" placeholder="请输入企业地址" class="layui-input" value="">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="bixuan">*</span>站类别：</label>
                    <div class="layui-input-block">
                        <select name="comptype" lay-search="">
                            <option value="2">施工单位</option>

                        </select>
                        <input type="text" name="securid_Compid" placeholder="" autocomplete="off" class="layui-input yinchang">
                    </div>
                </div>
                <div class="layui-form-iter gongliao">
                    <div class="layui-form-item">
                        <label class="layui-form-label">供料类型：</label>
                        <div class="layui-input-inline">
                            <select class="gongliaoon" lay-verify="required" lay-search="">


                            </select>
                            <input type="text" name="securid_Compid" placeholder="" autocomplete="off" class="layui-input yinchang">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="bixuan">*</span>联系电话：</label>
                    <div class="layui-input-block">
                        <input type="text" name="tel" lay-verify="required|phones" autocomplete="off" placeholder="请输入联系电话" class="layui-input" value="">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">传真：</label>
                    <div class="layui-input-block">
                        <input type="text" name="fax" 额 autocomplete="off" placeholder="请输入传真" class="layui-input" value="">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">联络人：</label>
                    <div class="layui-input-block">
                        <input type="text" name="contack" lay-verify="required" autocomplete="off" placeholder="请输入联络人" class="layui-input" value="">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">负责人：</label>
                    <div class="layui-input-block">
                        <input type="text" name="director" lay-verify="required" autocomplete="off" placeholder="请输入负责人" class="layui-input" value="">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="bixuan">*</span>负责人电话：</label>
                    <div class="layui-input-block">
                        <input type="text" name="dmotel" lay-verify="phones|required" autocomplete="off" placeholder="请输入负责人电话" class="layui-input" value="">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">纳税识别号：</label>
                    <div class="layui-input-block">
                        <input type="text" name="facno"  autocomplete="off" placeholder="请输入纳税识别号" class="layui-input" value="">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">邮政编码：</label>
                    <div class="layui-input-block">
                        <input type="text" name="postid"  autocomplete="off" placeholder="请输入邮政编码" class="layui-input" value="">
                    </div>
                </div>
                <!--<div class="layui-form-item">-->
                    <!--<label class="layui-form-label">英文名称：</label>-->
                    <!--<div class="layui-input-block">-->
                        <!--<input type="text" name="ename" lay-verify="required" autocomplete="off" placeholder="请输入英文名称" class="layui-input" value="">-->
                    <!--</div>-->
                <!--</div>-->
                <div class="layui-form-item" pane="">
                    <label class="layui-form-label">启用否</label>
                    <div class="layui-input-block choice">
                        <input type="radio" name="useing1" checked value="0" data="0" title="启用">
                        <input type="radio" name="useing1" value="1" data="1" title="禁用">

                        <!--<input type="radio" name="sex" value="禁" title="禁用" disabled="">-->
                    </div>
                    <input type="hidden" name="useing" value="0"  id="useing"/>
                    <input type="hidden" name="mark" value="1" id="mark" />
                    <input type="hidden" name="state" value="0" id="state"/>
                    <input type="hidden" name="compid" value="" id="compid"/>
                    <input type="hidden" name="compnames" value="" />

                </div>
                <div class="_submit">
                    <button class="layui-btn layui-btn-sm tijiao" lay-submit lay-filter="EN_tijiao">提交</button>
                    <!--<button class="layui-btn layui-btn-sm " type="reset">重置</button>-->
                </div>

              </form>
            </div>
        </div>

</div>


<script src="../../../resources/layui/layui.js" charset="utf-8"></script>
<script src="../../../resources/js/style.js"></script>
<script src="../../../resources/js/api.js"></script>

<script>
    function queryUser() {                          //查询
        var _inputVal=$('[name="username"]').val();        //获取输入框信息
        var compname=$('[name="compname"]').val();        //获取输入框信息
        var begintime=$('[name="begintime"]').val();        //获取输入框信息
        var endtime=$('[name="endtime"]').val();        //获取输入框信息
        _inputVal=$.trim(_inputVal);             //搜索框值去前后空格

        //console.log(_inputVal)
        if(!AntiSqlValid(_inputVal)) {
            if(lbq('api/comp/loadCompAllInfo.do')) {

                API.enterpriseInfor({                       //调用渲染页面
                    'type': 'a',
                    'compname': _inputVal,
                    'compname':compname,
                    'begintime':begintime,
                    'endtime':endtime,
                    'p': getCookie('yanzheng')
                })
            }
        }else{
            layer.msg('请勿输入特殊符号');
            $('[name="username"]').val('');
        }
    }


    function enterpriseAdd() {                  //企业添加
        layui.use(['form', 'layedit', 'laydate','table','element'], function(){
            var form = layui.form;
            $('.titleL').html('添加企业');
            $('.mask').show();
            $('.mask input').val('');
            $('#mark').val(1);          //隐藏域默认值赋值
            $('#useing').val(0);         //隐藏域默认值赋值
            $('#state').val(0);          //隐藏域默认值赋值
            $('.gongliao').hide();
            $("[name='comptype']").val('2');
            form.render('select');
            alertoff();
        })
    }
    
    
    layui.use(['form', 'layedit', 'laydate','table','element'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate
            ,table=layui.table
            ,element=layui.element;

        dayintishi('.dayin');
        panduanshijiantow('#test-limit3','#test-limit4',1000,1000,'.tijiao');     //查询 开始结束时间判断

        jiazais();

        $('.demoTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        if(lbq('api/comp/loadCompAllInfo.do')){
            API.enterpriseInfor({'type':'a','comptype':'2','p':getCookie('yanzheng')},function(){
                //console.log(arguments);

                form.render();//渲染下拉
            });      //调用页面数据查询 渲染
        }
        form.verify({
            phones: [
                /^[\S]{7,11}$/
                ,'请输入正确的联系方式'
            ]
        });


        //遮罩层隐藏

        $('.close').click(function () {
            $('.mask').hide();
            Btnoff('.tijiao');
        });

        //单选不生效  点击获取单选框值 付给隐藏域发送
        $('.choice').on('click','.layui-form-radio',function () {
            $('#useing').val($(this).prev().attr('data'))                   //读取自定义属性
            //console.log( $('#useing'))
        });


        //添加监听   检查企业名称是否存在
        $('.mask').find("[name='compname']").blur(function () {
            var _names=$(this).val();               //获取页面值
            _names=$.trim(_names);
            if(_names!=''){
                if(_names==$("[name=compnames]").val()){
                    return;
                }
                ajaxs('/api/public/cheName.do','get',{"type":1,"name":_names},function (data) {
                    //console.log(data)
                    if(data.data=='0'){

                        $('.tijiao').removeAttr('disabled').removeClass('layui-btn-disabled');
                    }else{
                        layer.msg('企业名称已存在 请重新输入');
                        $('.tijiao').attr('disabled',"true").addClass('layui-btn-disabled');
                    }
                })
            }
        })

        //日期
        laydate.render({
            elem: '#date1'      //开始时间
            ,type:'datetime'
        });
        laydate.render({
            elem: '#date2'  //结束时间
            ,type:'datetime'
        });

        //监听工具条
        table.on('tool(test)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值
            var tr = obj.tr; //获得当前行 tr 的DOM对象

            if(layEvent === 'detail'){ //查看
                //do somehing
                //console.log(obj)
                var datas=obj.data;
                datas.createtime=times(datas.createtime)
                datas.updatetime=times(datas.updatetime)


                if(datas.useing=='0'){
                    datas.useing='启用';
                }else{
                    datas.useing='禁用';
                }

                //console.log(datas)
                $('.titleL').html('查看企业');
                $('#mark').val(2);
                $('#compid').val(datas.compid);          //隐藏域默认值赋值
                $("[name='compname']").val(datas.compname);
                $("[name='shortname']").val(datas.shortname);
                $("[name='addr']").val(datas.addr);
                $("[name='tel']").val(datas.tel);
                $("[name='fax']").val(datas.fax);
                $("[name='contack']").val(datas.contack);
                $("[name='director']").val(datas.director);
                $("[name='dmotel']").val(datas.dmotel);
                $("[name='updid']").val(datas.updid);
                $("[name='facno']").val(datas.facno);
                $("[name='postid']").val(datas.postid);
                $("[name='ename']").val(datas.ename);
                $("[name='createtime']").val(datas.createtime);
                $("[name='updatetime']").val(datas.updatetime);
                $("[name='compnames']").val(datas.compname);
                $("[name='comptype']").val(datas.comptype);
                $('.yinchang').val(datas.comptype)
                $('[name="securid_Compid"]').val('施工单位')
                form.render();

               alerton();
                $('.main_onR').each(function () {
                    if($(this).html()=='null'||$(this).html()==null){
                        $(this).html('无')
                    }
                });
            } else if(layEvent === 'del'){ //删除
                layer.confirm('确认删除？', function(index){
                    obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
                    layer.close(index);
                    //向服务端发送删除指令
                });
            } else if(layEvent === 'edit'){ //编辑
                //do something
                var datas=obj.data;
                datas.createtime=times(datas.createtime)
                datas.updatetime=times(datas.updatetime)
                alertoff();

                //console.log(datas)
                $('.titleL').html('编辑企业');
                $('#mark').val(2);
                $('#compid').val(datas.compid);          //隐藏域默认值赋值
                $("[name='compname']").val(datas.compName);
                $("[name='shortname']").val(datas.shortname);
                $("[name='addr']").val(datas.addr);
                $("[name='tel']").val(datas.tel);
                $("[name='fax']").val(datas.fax);
                $("[name='contack']").val(datas.contack);
                $("[name='director']").val(datas.director);
                $("[name='dmotel']").val(datas.dmotel);
                $("[name='updid']").val(datas.updid);
                $("[name='facno']").val(datas.facno);
                $("[name='postid']").val(datas.postid);
                $("[name='ename']").val(datas.ename);
                $("[name='createtime']").val(datas.createtime);
                $("[name='updatetime']").val(datas.updatetime);
                $("[name='compnames']").val(datas.compName);
                $("[name='comptype']").val(datas.p_value);
                form.render();

                $('.mask').show()

            }
        });

        form.on('submit(EN_tijiao)', function(data){

            //console.log(data.field,'<-----------------') //当前容器的全部表单字段，名值对形式<span class="maohao">：</span>{name: value}

            Btnon('.tijiao');        //禁止提交按钮点击
            data.field.p=getCookie('yanzheng');
            formAlertAjax('/api/comp/inComp.do',data.field,'.tijiao');

            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

        inputs();       //检测input 是否为必填
    })

</script>
</body>
</html>